package com.love.marriage.matchmakerInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Insert;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.matchmakerInfo.service.MatchmakerInfoService;
import com.love.marriage.matchmakerInfo.vo.MatchmakerInfoVo;
import com.love.marriage.matchmakerInfo.vo.ResultMatchmakerInfoVo;
import com.love.marriage.matchmakerInfo.vo.ResultMatchmakerInfoVoPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * description:  红娘restApi
 * author:       alex
 * createDate:   2024-11-05 22:09:26
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "红娘", description = "红娘")
@RestController
@RequiredArgsConstructor
@RequestMapping("/matchmaker-info")
public class MatchmakerInfoController {

    private final MatchmakerInfoService matchmakerInfoService;

    @ApiOperationSupport(order = 10, author = "alex")
    @Operation(summary = "获取红娘分页", description = "获取红娘分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultMatchmakerInfoVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    public Result<Page<MatchmakerInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                  @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                  @RequestBody(required = false) MatchmakerInfoVo matchmakerInfoVo) {
        return Result.success(matchmakerInfoService.getPage(pageNum, pageSize, matchmakerInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "alex")
    @Operation(summary = "获取红娘详情", description = "获取红娘详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultMatchmakerInfoVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<MatchmakerInfoVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(matchmakerInfoService.queryMatchmakerInfo(id));
    }

    @ApiOperationSupport(order = 22, author = "alex")
    @Operation(summary = "根据用户id获取红娘详情（前端）", description = "根据用户id获取红娘详情(前端)")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultMatchmakerInfoVo.class
                    )))
    @Parameters({
            @Parameter(name = "userId", description = "userId", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping(value = "queryByUserId")
    public Result<MatchmakerInfoVo> queryByUserId(@RequestParam(value = "userId") Long userId) {
        return Result.success(matchmakerInfoService.queryNewMatchmakerByUserId(userId));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 25, author = "alex")
    @Operation(summary = "添加红娘信息(前端)", description = "添加红娘信息(前端)",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MatchmakerInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultMatchmakerInfoVo.class)))
    @PostMapping(value = "addInfo")
    public Result<MatchmakerInfoVo> addInfo(@Validated({Insert.class}) @RequestBody MatchmakerInfoVo matchmakerInfoVo) throws Exception {
        return Result.success(matchmakerInfoService.addInfo(matchmakerInfoVo));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "alex")
    @Operation(summary = "新增红娘", description = "新增红娘",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MatchmakerInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultMatchmakerInfoVo.class)))
    @PostMapping
    public Result<MatchmakerInfoVo> add(@Validated({Insert.class}) @RequestBody MatchmakerInfoVo matchmakerInfoVo) {
        return Result.success(matchmakerInfoService.addMatchmakerInfo(matchmakerInfoVo));
    }

    @ApiOperationSupport(order = 40, author = "alex")
    @Operation(summary = "修改红娘", description = "修改红娘",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = MatchmakerInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultMatchmakerInfoVo.class)))
    @PutMapping
    public Result<MatchmakerInfoVo> update(@Validated({Update.class}) @RequestBody MatchmakerInfoVo matchmakerInfoVo) {
        return Result.success(matchmakerInfoService.updateMatchmakerInfo(matchmakerInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "alex")
    @Operation(summary = "刪除红娘", description = "刪除红娘")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(matchmakerInfoService.deleteMatchmakerInfo(ids));
    }

    @ApiOperationSupport(order = 60, author = "alex")
    @Operation(summary = "导出红娘信息", description = "导出红娘信息到Excel文件")
    @ApiResponse(responseCode = "200", description = "Success", 
            content = @Content(mediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
    @PostMapping(value = "/export")
    public void export(@RequestBody(required = false) MatchmakerInfoVo matchmakerInfoVo, 
                       HttpServletResponse response) throws Exception {
        matchmakerInfoService.exportMatchmakerInfo(matchmakerInfoVo, response);
    }
}
